package com.idealighter.game.web.checklevel.shuihu.controller;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.idealighter.game.core.result.Result;
import com.idealighter.game.web.checklevel.shuihu.service.ShuiHuBasicControlCheck;
import com.idealighter.game.web.checklevel.shuihu.service.ShuiHuBasicControlCheck.ShuiHuIconInput;
import com.idealighter.game.web.checklevel.shuihu.service.ShuiHuBasicControlCheck.ShuihuCheckResult;
import com.idealighter.game.web.checklevel.shuihu.service.ShuiHuBasicControlCheck.ShuihuCheckResultDto;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuiHuBonusIconGroup;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuiHuBonusIconInput;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuiHuBonusInnerGroup;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuiHuBonusInnerInput;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuiHuBonusOuterGroup;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuiHuBonusOuterInput;
import com.idealighter.game.web.checklevel.shuihu.xml.ShuiHuXmlControlCheck.ShuihuBonusCheckResult;
import com.idealighter.utils.json.JsonUtil;
import java.util.List;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/checkLevel/shuhu")
@Singleton
public class ShuiHuCheckLevelController {
  @Inject
  private ShuiHuBasicControlCheck shuiHuBasicControlCheck;
  @Inject
  private ShuiHuXmlControlCheck shuiHuXmlControlCheck;

  /**
   * .
   * 
   * @param content .
   * @return .
   */
  @POST
  @Path("/basic")
  @Produces("application/json; charset=utf-8")
  public Result checkBasic(@FormParam("basic") String content) {
    List<ShuiHuIconInput> basicInputs = JsonUtil.fromJsonToList(content, ShuiHuIconInput.class);
    List<ShuihuCheckResult> checkResult = shuiHuBasicControlCheck.check(basicInputs);

    List<ShuihuCheckResultDto> checkResultDtos = ShuiHuBasicControlCheck.bo2dto(checkResult);

    Result result = new Result(true);
    result.getMap().put("list", checkResultDtos);
    return result;
  }

  /**
   * .
   * 
   * @param bonus .
   * @param innser .
   * @param outer .
   * @return .
   */
  @POST
  @Path("/xml")
  @Produces("application/json; charset=utf-8")
  public Result checkXml(@FormParam("bonus") String bonus, @FormParam("innser") String innser,
      @FormParam("outer") String outer) {
    // 小玛丽权重配置
    List<ShuiHuBonusIconInput> bonusInputs =
        JsonUtil.fromJsonToList(bonus, ShuiHuBonusIconInput.class);
    List<ShuiHuBonusInnerInput> innerInputs =
        JsonUtil.fromJsonToList(innser, ShuiHuBonusInnerInput.class);
    List<ShuiHuBonusOuterInput> outerInputs =
        JsonUtil.fromJsonToList(outer, ShuiHuBonusOuterInput.class);

    ShuiHuBonusIconGroup iconGroup = new ShuiHuBonusIconGroup(bonusInputs);
    ShuiHuBonusInnerGroup innerGroup = new ShuiHuBonusInnerGroup(innerInputs);
    ShuiHuBonusOuterGroup outerGroup = new ShuiHuBonusOuterGroup(outerInputs);
    ShuihuBonusCheckResult checkResult =
        shuiHuXmlControlCheck.checkXml(1000000, iconGroup, innerGroup, outerGroup);
    Result result = new Result(true);
    result.getMap().put("result", ShuiHuXmlControlCheck.bo2dto(checkResult));
    return result;
  }
}
